package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.NoticeBase;
import com.stylefeng.guns.modular.system.service.INoticeBaseService;

/**
 * 通知消息列表控制器
 *
 * @author fengshuonan
 * @Date 2019-10-07 01:38:18
 */
@Controller
@RequestMapping("/noticeBase")
public class NoticeBaseController extends BaseController {

    private String PREFIX = "/system/noticeBase/";

    @Autowired
    private INoticeBaseService noticeBaseService;

    /**
     * 跳转到通知消息列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "noticeBase.html";
    }

    /**
     * 跳转到添加通知消息列表
     */
    @RequestMapping("/noticeBase_add")
    public String noticeBaseAdd() {
        return PREFIX + "noticeBase_add.html";
    }

    /**
     * 跳转到修改通知消息列表
     */
    @RequestMapping("/noticeBase_update/{noticeBaseId}")
    public String noticeBaseUpdate(@PathVariable Integer noticeBaseId, Model model) {
        NoticeBase noticeBase = noticeBaseService.selectById(noticeBaseId);
        model.addAttribute("item",noticeBase);
        LogObjectHolder.me().set(noticeBase);
        return PREFIX + "noticeBase_edit.html";
    }

    /**
     * 获取通知消息列表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return noticeBaseService.selectList(null);
    }

    /**
     * 新增通知消息列表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(NoticeBase noticeBase) {
        noticeBaseService.insert(noticeBase);
        return SUCCESS_TIP;
    }

    /**
     * 删除通知消息列表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer noticeBaseId) {
        noticeBaseService.deleteById(noticeBaseId);
        return SUCCESS_TIP;
    }

    /**
     * 修改通知消息列表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(NoticeBase noticeBase) {
        noticeBaseService.updateById(noticeBase);
        return SUCCESS_TIP;
    }

    /**
     * 通知消息列表详情
     */
    @RequestMapping(value = "/detail/{noticeBaseId}")
    @ResponseBody
    public Object detail(@PathVariable("noticeBaseId") Integer noticeBaseId) {
        return noticeBaseService.selectById(noticeBaseId);
    }
}
